package com.bailian.mapper;

import com.bailian.mapper.entity.UserTokenDo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

public interface UserTokenMapper {

    @Select("SELECT id as id ,token as token ,login_type as LoginType, device_infor as deviceInfor ,is_availability as isAvailability,user_id as userId,create_time as createTime,update_time as updateTime FROM bailian_user_token WHERE user_id=#{userId} AND login_type=#{loginType} and is_availability ='0';")
    UserTokenDo selectByUserIdAndLoginType(@Param("userId") Long userId, @Param("loginType") String loginType);

    @Update("update bailian_user_token set is_availability ='1',update_time=now() where user_id=#{userId} and login_type =#{loginType} ")
    int updateTokenAvailability(@Param("userId") Long userId, @Param("loginType") String loginType);

    @Insert("INSERT INTO `bailian_user_token`(token,login_type,device_infor,is_availability,user_id,create_time,update_time) VALUES (#{token},#{loginType}, #{deviceInfor}, 0, #{userId} ,now(),now() ); ")
    int insertUserToken(UserTokenDo userTokenDo);
}